package com.yitianyigexiangfa.coap.cbor.jackson;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.yitianyigexiangfa.coap.cbor.util.ConvertUtil;

import java.io.IOException;

/**
 * @author Bill Lau
 * @date 2017-12-23
 */
public class JacksonDemo {

    public static void main(String[] args) throws IOException {
        CBORFactory f = new CBORFactory();
        ObjectMapper mapper = new ObjectMapper(f);
        String s = "happy";

        // ================== 编码 ==================
        byte[] cborData = mapper.writeValueAsBytes(s);
        System.out.println(ConvertUtil.bytesToHex(cborData));

        // ================== 解码 ==================
        String otherValue = mapper.readValue(cborData, String.class);
        System.out.println(otherValue);
    }

}
